home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Speech Unit Source / USpeaker.inc1.p < prev    next >
Encoding:
Text File  |  1993-09-02  |  3.3 KB  |  122 lines  |  [TEXT/MPS ]

  1. {    If you have any private types, uncomment the following line and add them }
  2. { TYPE }
  3.  
  4. {    Add implementations of your methods here }
  5.  
  6.     {The need for the following wait loop shows 
  7.     that statements following speech 
  8.     can happen concurrently, that is,
  9.     are immediately executed during speech!
  10.     For example, don't want to dispose his speech while the speaker is speaking!}
  11.  
  12.     PROCEDURE TSpeaker.WaitTilSpeechDone;
  13.         var delayLen: LONGINT;
  14.         begin
  15.             while    (NOT (SpeechBusy = 0)) do
  16.                 Delay(15, delayLen);
  17.         end;
  18.         
  19.     FUNCTION TSpeaker.GetChannel:SpeechChannel;
  20.         begin
  21.             GetChannel:= fChannel;
  22.         end;
  23.         
  24.     PROCEDURE TSpeaker.SetChannel(tc:SpeechChannel);
  25.         begin
  26.             fChannel:=tc;
  27.         end;
  28.  
  29.     {Liked the deep voice of Boris, most like Schwartznegger's, NumberOfVoice=6:}
  30.     PROCEDURE TSpeaker.ISpeaker(NumberOfVoice: Integer);
  31.         var response : LONGINT;
  32.             voiceCount:integer;
  33.             theChannel:    SpeechChannel;
  34.             myErr:        OSErr;
  35.             theVoiceSpecPtr:    VoiceSpecPtr;
  36.             theVoiceSpec:    VoiceSpec;
  37.         begin
  38.             
  39.             {Following are speech commands,
  40.             Put speech.p in Lab 7 folder,
  41.             so PMake would see it without too much auxiliary scripting:}
  42.             
  43.             myErr := Gestalt(gestaltSpeechAttr, response ) ;
  44.             if ((myErr <> noErr) or ((response=1) and 
  45.                         (1 < gestaltSpeechMgrPresent))) then HALT;
  46.             
  47.             {Some sort of initialization needed even if not do loop of all:}
  48.             myErr := CountVoices    (voiceCount);
  49.             
  50.             if (myErr <> noErr) then HALT;
  51.             
  52.             
  53.             if (NumberOfVoice<=voiceCount) then
  54.                 begin
  55.                     {Type transfer from generic pointer:}
  56.                     theVoiceSpecPtr := VoiceSpecPtr(@theVoiceSpec);
  57.                     
  58.                     {theVoiceSpecPtr is not var parm, so address value input,pass by address?}
  59.                     myErr := GetIndVoice          (NumberOfVoice, theVoiceSpecPtr);
  60.                     if (myErr <> noErr) then HALT;
  61.                     myErr := NewSpeechChannel     (theVoiceSpecPtr, theChannel);
  62.                     if (myErr <> noErr) then HALT;
  63.                     SetChannel(theChannel);
  64.                 end
  65.             else
  66.                 begin
  67.                     HALT;
  68.                 end;
  69.         end;
  70.                     
  71.     PROCEDURE TSpeaker.Free;OVERRIDE;
  72.         var myErr:        OSErr;
  73.     BEGIN
  74.         WaitTilSpeechDone;
  75.         myErr := DisposeSpeechChannel (fChannel);
  76.         if (myErr <> noErr) then HALT;
  77.         Dispose (SELF);
  78.     END;
  79.     
  80.     {
  81.     Comment on string lengths:
  82.     Pasted from Spinside mac 
  83.     Toolbox utilities:
  84.     String         'STR '               m bytes    The string (1-byte length
  85.                                                    followed by the characters)
  86.     THE MEMORY MANAGER 
  87.           Str255       = STRING[255];
  88.     My remarks (PMS):
  89.     8bits specify 2^8=256 possibilities (less one possibility of string 0 length) or 255
  90.     }
  91.     PROCEDURE TSpeaker.SpeakStr( ToSayString: Str255);
  92.         var textlen: LONGINT;
  93.             myErr:        OSErr;
  94.             theTextPtr:Ptr;
  95.         begin
  96.             
  97.             {Note: @ToSayString= @ToSayString[0] would tell length of text, since ToSayString:Str255,
  98.             so we use @ToSayString[1] to start reading where we want to below:}
  99.             theTextPtr:=Ptr(@ToSayString[1]);
  100.             
  101.             {Since we started reading at the right byte, we have the expected text length:}
  102.             textlen:=Ord4(LENGTH(ToSayString));
  103.  
  104.             {OK now we have set up and it can speak:}            
  105.             myErr := SpeakText (GetChannel,theTextPtr,textlen);
  106.             if (myErr <> noErr) then HALT;
  107.  
  108.         end;
  109.         
  110.     PROCEDURE TSpeaker.SpeakTxt(theTextHdl:Handle);
  111.         var textlen: LONGINT;
  112.             myErr:        OSErr;
  113.             theTextPtr:Ptr;
  114.         begin
  115.             textlen := GetHandleSize(theTextHdl);
  116.             theTextPtr:= theTextHdl^;
  117.             
  118.             {OK now we have set up and it can speak:}            
  119.             myErr := SpeakText (GetChannel,theTextPtr,textlen);
  120.             if (myErr <> noErr) then HALT;
  121.         end;
  122.